import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  listTenantUser = '/system-service/tenantUser/pageUser',
  get = '/system-service/tenantUser/getUserDetails',
  assignUser='/system-service/tenantUser/assignUser',
  edit='/system-service/tenantUser/update',
  getUserRole = '/system-service/user/listUserRole',
  duplicateCheck = '/system-service/duplicate/check',
  deleteUser = '/system-service/tenantUser/delete',
  deleteBatch = '/system-service/tenantUser/deleteBatch',
  importExcel = '/system-service/tenantUser/importExcel',
  exportXls = '/system-service/tenantUser/exportXls',
  recycleBinList = '/system-service/tenantUser/recycleBin',
  recoverRecycleBin = '/system-service/tenantUser/recoverRecycleBin',
  deleteRecycleBin = '/system-service/tenantUser/deleteRecycleBin',
  pageUserInvite = "/system-service/tenantUser/pageInvite",
  saveUserInvite = "/system-service/tenantUser/saveInvite",
  getUserInvite = "/system-service/tenantUser/getInvite",
  getUserInviteBySign = "/system-service/tenantUser/getInviteBySign",
  disableInvite = "/system-service/tenantUser/disableInvite",
  userJoinTenant = "/system-service/tenantUser/joinTenant",

  allRolesList = '/system-service/role/listAllRole',
  allTenantList = '/system-service/tenant/listAll',
  allPostList = '/system-service/position/listAll',
  listUserDept = '/system-service/tenantUser/listUserDept',
  listTenant = '/system-service/user/profile/listTenant',
}

export const getExportUrl = Api.exportXls;

export const getImportUrl = Api.importExcel;

export const listTenantUser = (params) => 
  defHttp.get({url: Api.listTenantUser, params});

/**
 * @param params
 */
export const getUserDetails = (params) => 
  defHttp.get({url: Api.get, params});

export const pageUserInvite = (params) => {
  return defHttp.get({url : Api.pageUserInvite, params});
}

export const saveUserInvite = (params) => {
  return defHttp.post({url: Api.saveUserInvite, params});
}

export const getUserInvite = (params) => {
  return defHttp.get({url: Api.getUserInvite, params});
}
export const disableInvite = (params) => {
  return defHttp.put({url: Api.disableInvite, params }, { joinParamsToUrl: true });
}

export const getUserInviteBySign = (params) => {
  return defHttp.get({url: Api.getUserInviteBySign, params}, { isTransformResponse: false });
}

export const userJoinTenant = (params) => {
  return defHttp.post({url: Api.userJoinTenant, params}, { joinParamsToUrl: true , isTransformResponse: false});
}

export const getUserRoles = (params) =>
  defHttp.get({url: Api.getUserRole, params}, {errorMessageMode: 'none'});

export const deleteUser = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteUser, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const batchDeleteUser = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}

export const assignUser = (params, handleSuccess) => {
  return defHttp.post({url: Api.assignUser, params}).then(() => {
    handleSuccess();
  });
}

export const updateUser = (params) => {
  return defHttp.post({url: Api.edit, params});
}

export const duplicateCheck = (params) => defHttp.get({url: Api.duplicateCheck, params},{isTransformResponse:false});

export const getAllRolesList = (params) => defHttp.get({url: Api.allRolesList, params});

export const getAllTenantList = (params) => defHttp.get({url: Api.allTenantList, params});

/**
 * 获取指定用户负责部门
 */
export const getUserDeptList = (params) =>
  defHttp.get({url: Api.listUserDept, params},{successMessageMode:'none'});
/**
 * 获取全部职务
 */
export const getAllPostList = (params) => {
  return new Promise((resolve) => {
    defHttp.get({url: Api.allPostList, params}).then(res => {
      resolve(res.records)
    });
  })
}
/**
 * 回收站列表
 * @param params
 */
export const getRecycleBinList = (params) => defHttp.get({url: Api.recycleBinList, params});

/**
 * 回收站还原
 * @param params
 */
export const recoverRecycleBin = (params,handleSuccess) =>{
  return defHttp.put({url: Api.recoverRecycleBin, params}).then(() => {
    handleSuccess();
  });
}

export const deleteRecycleBin = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteRecycleBin, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const listLoginUserTenant = () => {
  return defHttp.get({url: Api.listTenant, params: {}});
}

  